package gazzera.swing.browse;

import gazzera.swing.browse.items.*;
import gazzera.swing.utility.*;

import java.awt.*;

import javax.swing.*;
import javax.swing.tree.*;


class MyRenderer extends DefaultTreeCellRenderer {
    Icon networkIcon;
    Icon userIcon;
    Icon folderIcon;
    Icon fileIcon;
    Icon folderToLoadIcon;
    Icon loadingIcon;

    public MyRenderer() {
	    networkIcon = new ImageIcon(ResourceLoader.get("world.png"));
	    userIcon = new ImageIcon(ResourceLoader.get("folder_user.png"));
	    folderIcon = new ImageIcon(ResourceLoader.get("tree_folder.png"));
	    folderToLoadIcon = new ImageIcon(ResourceLoader.get("folder_go.png"));
	    fileIcon = new ImageIcon(ResourceLoader.get("page.png"));
	    loadingIcon = new ImageIcon(ResourceLoader.get("view-refresh.png"));
    }

    public Component getTreeCellRendererComponent(
                        JTree tree,
                        Object value,
                        boolean sel,
                        boolean expanded,
                        boolean leaf,
                        int row,
                        boolean hasFocus) 
    {

        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,hasFocus);
        
        
        
        if (value instanceof NetworkItem) 
        {
            setIcon(networkIcon);
        } 
        else if (value instanceof UserItem) 
        {
            setIcon(userIcon);
        } 
        else if (value instanceof FolderItem) 
        {
            FolderItem i = (FolderItem)value;
            if(!i.isLoaded())
            {
            	setIcon(folderToLoadIcon);
            }
            else
            {
            	setIcon(folderIcon);
            }
        } 
        else if (value instanceof LoadingItem) 
        {
            setIcon(loadingIcon);
        } 
        else 
        {
            setIcon(fileIcon);
        } 

        return this;
    }

}